<%@page import="java.rmi.RemoteException"%>
<%@page import="java.sql.SQLException"%>


<%@page import="org.apache.jsp.ForumHtml.notifier_jsp"%>
<%@page import="exception.NotLoggedInException"%>
<%@page import="clientData.ForumDataInt"%>
<%@page import="java.util.LinkedList"%>
<%@page import="java.util.Vector"%>
<%@page import="java.rmi.Naming"%>
<%@page import="server.ForumHandlerInt"%>
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Forums</title>
    <%@ include file="scripts.jsp" %>
    <script src="includes/ice/ice.js" type="text/javascript"></script>
<script language="Javascript">
		function procLink(fId,fName) {
			document.foo.forumId.value = fId
			document.foo.forumName.value = fName
			document.foo.submit()
		}
	</script>
    
    <link href="styles.css" rel="stylesheet" type="text/css">
    <link href="tableDesign.css" rel="stylesheet" type="text/css">
    <script language="JavaScript" type="text/JavaScript">
		<!--
		function MM_preloadImages() { //v3.0
		  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
			var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
		}
		-->
	</script>
</head>

<%@ include file="serverConnection.jsp" %>
<%

	if (session.getAttribute("userName")==null)
	{
		response.sendRedirect("loggin.jsp");
		response.flushBuffer();
		return;
	}

%>




<body link="#6C8EBD">
<div id="main"> 
	<div id="header">
		<div id="logo"><img src="Images/logo1.jpg" alt="logo" width="490" height="182"></div>
		<div id="picture"><img src="Images/logo2.jpg" alt="pic" width="289" height="156"></div>
	</div>
	<div id="line"><img src="Images/line.jpg" alt="line" width="779" height="4"></div>
    <div id="navigation">
		forums screen
	</div>
	<div id="line2"><img src="Images/line.jpg" alt="line" width="779" height="4"></div>
	<div id="text" ice:editable="*">
		<div id="bar">
			<div class="bluetxt" id="linktxt">
                <p> <a href="friends.jsp" class="bluetxt">manage friends</a> </p>
      <%if (((String)session.getAttribute("permission")).equals("ADMIN")){ %>
  	  	<p><a href="addForum.jsp" class="bluetxt">addForum</a> </p> 
  	  <%} %>
      <p><a href="index.jsp"  class="bluetxt" target="_top" onClick= "logoutFunc();">logout</a>  </p> 			
			</div>
		</div>
		<div id="text2">
			<div class="contentTXT" id="text2txt">
			  
<table border=2 style="margin-left: 200px; color: #000;">

<%
LinkedList<ForumDataInt> forums = null;


try
{
	 forums = forum.getForumList((String)session.getAttribute("userName"),(String)session.getAttribute("password"));
}
catch(NotLoggedInException t)
{

	response.sendRedirect("loggin.jsp");
	response.flushBuffer();
	return;
	
}
catch(SQLException s){
	//System.out.println("SQL EXCEPTION");
	   
	response.sendError(response.SC_INTERNAL_SERVER_ERROR,
	"SQL server is down");

	response.flushBuffer();
	return;
}
catch(RemoteException u){
	   
	   response.sendError(response.SC_INTERNAL_SERVER_ERROR,
		"forum server is down");
	
		response.flushBuffer();
		return;
}


%>
<thead>
    <tr>
    <th>FORUM NAME</th>
    <th>FORUM CREATOR</th>
    </tr>
</thead>
<tbody>
<%
	
    for ( ForumDataInt fd:forums ) {
        %>
        <tr>
  
        <td><a href="javascript:void(1);" onClick="procLink('<%=fd.getId()%>','<%=fd.getName()%>');"><%=fd.getName() %></a></td>
        <td><%= fd.getCreator().getUserName()%></td>
        </tr>
        <%
    }
%>

</tbody>
</table>
			</div>
		</div>
	</div>
<div id="Num"><img src="Images/line.jpg" alt="line" width="779" height="4"></div>
<div id="footer">
<div class="footerTXT" id="footertxt"><a class="footerTXT">Designed by ariel nir yuri gilad itzhaki and marina</a> </div>   </div>
</div>
</div>

<form name="foo" method=post action="topics.jsp">
	<input type="hidden" name="forumId" value="">
	<input type="hidden" name="forumName" value="">
</form>
</body>
</html>

